/**
  * Description:
  *      以实际用户身份测试相应文件权限
  */

#include "apue.h"
#include <fcntl.h>

int main(int argc, char *argv[]) {
    if (argc != 2)
        err_quit("usage: %s faccessat <pathname>", argv[0]);
    if (faccessat(AT_FDCWD, argv[1], R_OK, AT_EACCESS))
        err_ret("faccessat error for %s", argv[1]);
    else
        printf("read access OK\n");

    if (open(argv[1], O_RDONLY) < 0)
        err_ret("open error for %s", argv[1]);
    else
        printf("open for reading OK\n");
    return 0;
}